<template>
    <div class="intergration-wrapper">
        <centerHeader/>
        <div class="centerCate-wrap">
            <div class="info-box">
                <div class="box-l">
                    <ul>
                        <li>
                            <p class="box_name">
                                <span class="title-01">{{user_info.username}}</span>
                                <span class="title-01">({{user_info.mobile}})</span>
                            </p>
                        </li>
                        <li>
                            <p>
                                <el-radio v-model="sex" label="1">男</el-radio>
                                <el-radio v-model="sex" label="2">女</el-radio>
                            </p>
                        </li>
                    </ul>
                </div>

                <div class="submit-box">
                    <button class="submit-btn" @click="submit">保存</button>
                </div>
            </div>
        </div>
        <centerFooter/>
    </div>
</template>

<script type="text/ecmascript-6">
    import centerHeader from "@/views/center/components/centerHeader";
    import centerFooter from "@/views/center/components/centerFooter";
    import constant from "@/utils/constant.js";
    // 引用API文件
    import http from "@/utils/http.js";

    export default {
        name: "sex",
        data() {
            return {
                isBuy: true,
                user_info: {},
                sex: 0
            };
        },
        components: {
            centerHeader,
            centerFooter
        },
        methods: {
            userinfo() {
                http.get(this, {
                    url: "ucenter/user_info",
                    data: {
                        token: localStorage.getItem("user_token")
                    },
                    dataType: "json",
                    success: function(data) {
                        console.log("用户信息:", data);
                        if (data.status == 1) {
                            this.user_info = data.info;
                            this.sex = this.user_info.sex;
                        } else {
                        }
                    }
                });
            },
            submit() {
                let user_type = localStorage.getItem("user_type")

                if(user_type != 'store'){
                    http.post(this, {
                        url: "ucenter/personal",
                        data: {
                            token: localStorage.getItem("user_token"),
                            sex:this.sex
                        },
                        dataType: "json",
                        success: function(data) {
                            console.log("保存用户信息:", data);
                            if (data.status == 1) {
                                window.history.go(-1)
                            } else {
                            }
                        }
                    });
                }else if(user_type == 'store'){
                    http.post(this, {
                        url: "store/personal",
                        data: {
                            token: localStorage.getItem("user_token"),
                            sex:this.sex
                        },
                        dataType: "json",
                        success: function(data) {
                            console.log("保存用户信息:", data);
                            if (data.status == 1) {
                                window.history.go(-1)
                            } else {
                            }
                        }
                    });
                }

            }
        },
        created() {},
        activated() {
            this.userinfo();
        }
    };
</script>

<style scoped lang="scss">
    .intergration-wrapper {
    }

    .centerCate-wrap {
        width: 100%;
        text-align: center;

        .info-box {
            @extend .cmm-clearfix;
            $letHeight: 1rem;
            min-height: $letHeight;
            padding: 0.22rem 0;

            .box-l {

                position: relative;
                min-height: $letHeight;
                margin-left: 0.2rem;
                margin-right:0.2rem;
            }

            .box-r {
                float: right;
                position: relative;
                width: 1rem;
                height: $letHeight;

                .icon-02 {
                    float: right;
                    font-size: 0.6rem;
                    @extend .cmm-translateXY;
                }
            }
        }

        ul {
            width: 100%;
            $letHeight: 0.5rem;

            li {
                line-height: $letHeight;

                p {
                    color: $c-mainC;
                    @extend .cmm-clearfix;
                    height: $letHeight;

                    * {
                        line-height: $letHeight;
                        display: inline-block;
                        vertical-align: middle;
                    }

                    a {
                        width: 100%;
                    }

                    .icon-02 {
                        float: right;
                        font-size: 0.6rem;
                    }

                    .title-01 {
                        font-size: 0.32rem;
                        float: left;
                        color: $c-mainC;
                        font-weight: 500;
                    }

                    .title-03 {
                        font-size: 0.22rem;
                        float: left;
                        color: $c-mainC;
                    }
                }
            }
        }
    }

    .icon-03 {
        font-size: 0.7rem;
        line-height: 0.8rem;
        vertical-align: middle;
        font-weight: 100;
        width: 0.5rem;
        display: inline-block;
    }

    .submit-box {
        padding: 0 0.66rem;
        margin-top: 0;
    }
    .box_name{
        display: flex;
        justify-content: center;
    }
    /deep/.el-radio__inner{
        width:0.4rem;
        height:0.4rem;
    }
    /deep/.el-radio__label{
        font-size: 0.3rem;
    }
</style>
